<?php

use App\Admin\Controller\Base\SuperConfigController;
use App\Admin\Service\Base\SuperConfigService;
use App\Common\Enums\Base\SuperConfigEnumType;
use App\Common\Model\Base\SuperConfig;
use App\Common\Util\TP;
use Sc\Util\HtmlStructure\Form;
use Sc\Util\HtmlStructure\Form\FormItem;
use Sc\Util\HtmlStructure\Html\Html;

Html::create('添加超级配置');

$form = Form::create('superConfigForm')->config('label-width', '80px');

$form->addFormItems(
    FormItem::hidden('id', 'ID'),
    FormItem::group(
        FormItem::inLine(
            FormItem::text('sign', '配置签名')->col(6),
            FormItem::text('name', '配置名称')->col(6),
            FormItem::radio('type', '配置类型')->options(SuperConfigEnumType::mapping()),
        )
    ),
    FormItem::group("配置详情（数组与键值对类型无需配置）")->addItems(
        FormItem::table('config_info')->addItems(
            FormItem::text('title', '名称'),
            FormItem::text('field', 'KEY'),
            FormItem::select('formType', '表单类型')->options(SuperConfigService::supportForm()),
            FormItem::select('extra', '扩展信息')->placeholder('请键入')
                ->setVAttrs('allow-create',)
                ->setVAttrs('multiple',)
                ->setVAttrs('clearable')
                ->setVAttrs('default-first-option'),
        )
    ),
    FormItem::submit()->successClose('parent')->submitUrl(
        TP::route()->to([SuperConfigController::class, 'store'])->url(),
        TP::route()->to([SuperConfigController::class, 'update'])->url(),
    )->success('parent.VueApp.super_configGetData()')
);
if (TP::request()->get('id')) {
    $form->setData(SuperConfig::find(TP::request()->get('id'))->toArray());
}

return $form->render();